<?php
/**
 * Created by Shijie Liu. 2017/6/20
 * 生成订单,商品信息+用户信息
 */
//    print_r(CreateOrder(2));

    function CreateOrder($kind)
    {

        $con_db = mysqli_connect("localhost", "root", "19971010", "book_store");
        $user_id = $_COOKIE["user_login"];

        $order_shop = array(array());
        $order_user = array(array());

        if (isset($user_id)){
            $query = $sql_o = "SELECT book.book_name,book.book_author,book_cart.num,book.book_price,
        (book.book_price*book_cart.num) as sum from book,book_cart,user 
        where book_cart.book_id = book.book_id AND user.user_id = book_cart.user_id AND user.user_id= $user_id;";;
            $query .= "SELECT user_name,user_id,user_address FROM user where user_id  = $user_id;";


            $result = mysqli_multi_query($con_db, $query);

            if ($result != false) {

                if ($result_1 = mysqli_store_result($con_db)) {   //获取当前的结果集

                    $row = mysqli_fetch_all($result_1);
                    $order_shop = $row;
                    mysqli_free_result($result_1);
                } else {
                    $order_shop[0][0] = 0;
                }

                mysqli_next_result($con_db);  //指针下移

                if ($result_2 = mysqli_store_result($con_db)) {  //获取第二个结果集
                    $row = mysqli_fetch_all($result_2);
                    $order_user = $row;
                    mysqli_free_result($result_2);
                } else {
                    $order_user[0][0] =  0;
                }
            } else {
                $order_shop[0][0] = $order_user[0][0] = 0;   //查询失败
            }
            $con_db->close();
        }else{
            $order_shop[0][0] = $order_user[0][0] = 2;   //未登录
        }

        switch ($kind) {
            case 1:
                return $order_shop;
                break;
            case 2:
                return $order_user;
                break;
        }
    }